/*
 * Copyright 2013 floreysoft GmbH (www.floreysoft.net)
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.floreysoft.gwt.drive.client.realtime;

import com.floreysoft.gwt.drive.client.utils.JavaScriptUtils;

/**
 * Errors that can occur while loading or collaborating on a document.<p>
 * 
 * <code>CLIENT_ERROR</code> An internal error occurred in the Drive Realtime API
 * client. <p>
 * 
 * <code>CONCURRENT_CREATION</code> Another user created the document's initial state
 * after gapi.drive.realtime.load was called but before the local creation was
 * saved. <p>
 * 
 * <code>FORBIDDEN</code> The user associated with the provided OAuth token is not
 * authorized to access the provided document ID.<p>
 * 
 * <code>INVALID_COMPOUND_OPERATION</code> A compound operation was still open at the
 * end of a synchronous block. Compound operations must always be ended in the
 * same synchronous block that they are started. <p>
 * 
 * <code>NOT_FOUND</code> The provided document ID could not be found. <p>
 * 
 * <code>SERVER_ERROR</code> An internal error occurred in the Drive Realtime API
 * server. <p>
 * 
 * <code>TOKEN_REFRESH_REQUIRED</code> The provided OAuth token is no longer valid and
 * must be refreshed.<p>
 * 
 * 
 */
public enum ErrorType implements JavaScriptEnum<String> {
	CONCURRENT_CREATION("CONCURRENT_CREATION"), 
	FORBIDDEN("FORBIDDEN"), 
	INVALID_COMPOUND_OPERATION("INVALID_COMPOUND_OPERATION"), 
	NOT_FOUND("NOT_FOUND"), 
	SERVER_ERROR("SERVER_ERROR"), 
	TOKEN_REFRESH_REQUIRED("TOKEN_REFRESH_REQUIRED"), 
	CLIENT_ERROR("CLIENT_ERROR");

	public String value;

	private ErrorType(String value) {
		this.value = value;
	}

	/**
	 * Finds the action by value
	 * 
	 * @param value
	 *            The value
	 * @return The action
	 */
	public static EventType findByValue(String value) {
		for (EventType action : EventType.values()) {
			if (action.getValue().equals(value)) {
				return action;
			}
		}
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String getValue() {
		return JavaScriptUtils.enumValue("ErrorType", value);
	}

}
